<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .arrow {
            width: 100px;
            height: 10px;
            position: relative;
            border: 1px solid black;
            margin: 400px auto;
            background-color: black;
        }

        .arrow::after {
            content: "";
            display: block;
            width: 0;
            height: 0;
            border-left: 10px solid transparent;
            border-right: 10px solid transparent;
            border-bottom: 20px solid black;
            /* 箭头的颜色 */
            position: absolute;
            top: 50%;
            right: -20px;
            transform: translate(0, -50%) rotate(90deg);
        }

        .arrow::before {
            content: "";
            display: block;
            width: 20px;
            height: 20px;
            border: 1px solid #000;
            background-color: black;
            border-radius: 100%;
            /* 箭头的颜色 */
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }
    </style>
</head>

<body>
    <!-- 箭头元素 -->
    <div id="arrow" class="arrow">
    </div>

    <script>
        const arrow = document.getElementById('arrow');
        document.addEventListener('mousemove', function (event) {

            const x = event.clientX;
            const y = event.clientY;
            const centerX = window.innerWidth / 2;
            const centerY = window.innerHeight / 2;

            // 计算鼠标位置与中心点的角度
            const angle = Math.atan2(y - centerY, x - centerX) * (180 / Math.PI);

            // 设置箭头的旋转角度
            arrow.style.transform = `translate(-50%, -50%) rotate(${angle}deg)`;
        });
    </script>
</body>

</html>